import { Controller } from "../../mvc/core/Controller";
import { WareHouseProxy } from "../proxy/WareHouseProxy";
import { WareHouseExtendProxy } from "../proxy/WareHouseExtendProxy";
import { PackProxy } from "../proxy/PackProxy";
import { Cache } from "../cache/Cache";
import { DataEvent } from "../events/DataEvent";
import { DragDropData } from "../view/pack/DragDropData";
import { GameProxy } from "../mvc/GameProxy";
import { ItemData } from "../resource/info/ItemData";
import { GameController } from "../mvc/GameController";
import { IPackModule } from "../../../modules/interfaces/IPackModule";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { MsgManager } from "../manager/MsgManager";
import { EPlayerItemPosType } from "../../../Message/Public/EPlayerItemPosType";
import { ECategory } from "../../../Message/Public/ECategory";
import { EProp } from "../../../Message/Public/EProp";
import { BackPackWareHouseMoveType } from "../view/pack/define/BackPackWareHouseMoveType";
import { DataProvider } from "../../../fl/data/DataProvider";
import { GlobalClass } from "../../../com/mui/core/GlobalClass";
import { SBagCapacityChangeMsg } from "../../../Message/Game/SBagCapacityChangeMsg";
import { LayerManager } from "../manager/LayerManager";
import { WareHouseItem } from "../view/wareHouse/WareHouseItem";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { PackCache } from "../cache/PackCache";
import { IView } from "../../mvc/interfaces/IView";
import { WareHouseModule } from "../../../modules/WareHouseModule";
import { WindowEvent } from "../../component/window/WindowEvent";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { SMoney } from "../../../Message/Game/SMoney";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { WareHousePosTypeCache } from "../cache/WareHousePosTypeCache";
import { PackPosTypeCache } from "../cache/PackPosTypeCache";
import { WareHouseExtendPosTypeCache } from "../cache/WareHouseExtendPosTypeCache";
type int = number;
//class WareHouseController
    
    export  class WareHouseController extends Controller
    {
        constructor()
        {
            
            super();this._wareHouseProxy = new WareHouseProxy();
            this._wareHouseExtendProxy = new WareHouseExtendProxy();
            this._packProxy = new PackProxy();
            this._wareHouseCache = Cache.instance.pack.wareHousePackCache;
            this._packCache = Cache.instance.pack.backPackCache;
            this._wareHouseExtendCache = Cache.instance.pack.wareHouseExtendPackCache;
            return;
        }

        /* internal  */takeOut(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=0;
            var loc8=null;
            var loc9=0;
            var loc10=0;
            var loc11=null;
            var loc1=this._wareHouseModule.selectIndex;
            if (loc1 >= 0) 
            {
                loc2 = this._wareHouseModule.selectItemData;
                if (!loc2) 
                {
                    return;
                }
                loc3 = loc2.uid;
                loc4 = 1;
                loc5 = 0;
                loc6 = this._wareHouseModule.selectIndex;
                loc7 = Cache.instance.pack.backPackCache.itemLength;
                loc8 = Cache.instance.pack.backPackCache.getAllItems();
                loc9 = 0;
                while (loc9 < loc8.length) 
                {
                    if (!Cache.instance.pack.backPackCache.getItemDataByIndex(loc9 + 1)) 
                    {
                        loc10 = Cache.instance.pack.wareHousePackCache.getIndexByUid(loc3);
                        loc11 = new DragDropData(loc4, loc5, loc3, loc10, loc9 + 1, loc2, null);
                        GameProxy.packProxy.move(loc11);
                        return;
                    }
                    ++loc9;
                }
            }
            else 
            {
                return;
            }
            return;
        }

        /* internal  */updateItems(arg1: Object): void
        {
            var loc4=null;
            if (!_view) 
            {
                return;
            }
            this.updateDataChange();
            return;
            this._wareHouseModule.updateItem(this.dataProvider);
            this._wareHouseModule.updateCapacity(Cache.instance.pack.wareHousePackCache);
            if (arg1) 
            {
                if (arg1["selectIndex"] == -1) 
                {
                    this._wareHouseModule.updateWareHouseItemPanelSelectItem(-1);
                }
                else 
                {
                    this._wareHouseModule.updateWareHouseItemPanelSelectItem((arg1["selectIndex"] - 1));
                }
            }
            return;
        }

        /* internal  */wareHouse_DragInExtendItem(arg1: DataEvent): void
        {
            var loc3=0;
            var loc8=null;
            var loc9=null;
            var loc10=0;
            var loc11=false;
            this.page = this._wareHouseModule.pageTabBarSelect;
            var loc1=arg1.data as DragDropData;
            var loc2=loc1.fromPosType;
            var loc4=loc1.toIndex;
            var loc5=loc1.uid;
            var loc6=loc1.toPosType;
            var loc7=Cache.instance.pack.getPackChacheByPosType(loc6).getItemDataByIndex(loc4) as ItemData;
            var loc12=loc2;
            switch (loc12) 
            {
                case 0:
                {
                    loc3 = loc1.fromIndex + 42 * (GameController.pack.view as IPackModule).pageTabBarSelect;
                    loc8 = Cache.instance.pack.getPackChacheByPosType(loc2).getItemDataByIndex(loc3) as ItemData;
                    this.moveExtendItem(loc1, this._wareHouseExtendProxy);
                    break;
                }
                case 1:
                {
                    loc3 = loc1.fromIndex + 30 * this.page;
                    loc1.fromIndex = loc3;
                    loc8 = Cache.instance.pack.getPackChacheByPosType(loc2).getItemDataByIndex(loc3) as ItemData;
                    this.moveExtendItem(loc1, this._wareHouseExtendProxy);
                    break;
                }
                case 5:
                {
                    loc3 = loc1.fromIndex;
                    loc8 = Cache.instance.pack.getPackChacheByPosType(loc2).getItemDataByIndex(loc3) as ItemData;
                    this.moveExtendItem(loc1, this._wareHouseExtendProxy);
                    break;
                }
                case 6:
                {
                    loc3 = loc1.fromIndex;
                    loc8 = Cache.instance.pack.getPackChacheByPosType(loc2).getItemDataByIndex(loc3) as ItemData;
                    if (loc4 <= Cache.instance.pack.wareHouseExtendPackCache.sbag.capacity) 
                    {
                        this._wareHouseExtendProxy.moveInBag(loc5, loc4, loc3);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        /* internal  */moveExtendItem(arg1: DragDropData, arg2): void
        {
            var dragDropData: DragDropData;
            var proxy;
            var len: int;
            var toItemIsExtend: Boolean;
            var _cache;
            var _proxy;
            var toItemCategory: int;
            var toItemProp: int;
            var toItemData: ItemData;
            var fromItemData: ItemData;
            var fromIndex: int;
            var toIndex: int;
            var fromPosType: int;
            var toPosType: int;
            var uid: string;
            var isTidy: Boolean;
            var pathOfDrag: string;
            var showAlterWindow: Function;

            var loc1;
            len = 0;
            toItemIsExtend = false;
            _cache = undefined;
            _proxy = undefined;
            toItemCategory = 0;
            toItemProp = 0;
            toIndex = 0;
            isTidy = false;
            pathOfDrag = null;
            dragDropData = arg1;
            proxy = arg2;
            showAlterWindow = (arg1: string, arg2: Boolean, arg3: string=null): void
            {
                var posName: string;
                var _isTidy: Boolean;
                var path: string=null;
                var closeHandler1: Function;

                var loc1;
                posName = arg1;
                _isTidy = arg2;
                path = arg3;
                if (_cache.getLengthOfNullItemFromAllItem() >= len) 
                {
                    closeHandler1 = (arg1: int): void
                    {
                        if (arg1 == Alert.YES) 
                        {
                            if (toIndex <= _cache.sbag.capacity) 
                            {
                                _proxy.move(dragDropData, _isTidy, path);
                            }
                        }
                        return;
                    }
                    Alert.show(Language.getStringByParam(42503, posName), null, Alert.YES | Alert.CANCEL, null, closeHandler1);
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(42504, posName));
                }
                return;
            }
            toItemData = dragDropData.toItemData;
            fromItemData = dragDropData.fromItemData;
            fromIndex = dragDropData.fromIndex;
            toIndex = dragDropData.toIndex;
            fromPosType = dragDropData.fromPosType;
            toPosType = dragDropData.toPosType;
            uid = dragDropData.uid;
            if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar) 
            {
                if (toIndex <= Cache.instance.pack.backPackExtendPackCache.sbag.capacity) 
                {
                    this._wareHouseExtendProxy.move(dragDropData);
                }
            }
            if (toItemData != null) 
            {
                toItemCategory = toItemData.itemInfo.item.category;
                toItemProp = toItemData.itemInfo.item.type;
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse) 
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    if (toItemCategory == ECategory._ECategoryProp && toItemProp == EProp._EPropPackage) 
                    {
                        pathOfDrag = BackPackWareHouseMoveType.WareHouseExtendToWareHouse;
                        len = fromItemData.itemInfo.item.effect - toItemData.itemInfo.item.effect;
                        toItemIsExtend = true;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar) 
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    if (toItemCategory == ECategory._ECategoryProp && toItemProp == EProp._EPropPackage) 
                    {
                        pathOfDrag = BackPackWareHouseMoveType.WareHouseToWareHouseExtend;
                        toItemIsExtend = true;
                        len = fromItemData.itemInfo.item.effect - toItemData.itemInfo.item.effect;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBag && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar) 
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                    if (toItemCategory == ECategory._ECategoryProp && toItemProp == EProp._EPropPackage) 
                    {
                        pathOfDrag = BackPackWareHouseMoveType.BackPackToWareHouseExtend;
                        toItemIsExtend = true;
                        len = fromItemData.itemInfo.item.effect - toItemData.itemInfo.item.effect;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse) 
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    if (toItemCategory == ECategory._ECategoryProp && toItemProp == EProp._EPropPackage) 
                    {
                        pathOfDrag = BackPackWareHouseMoveType.BackPackExtendToWareHouse;
                        toItemIsExtend = true;
                        len = fromItemData.itemInfo.item.effect - toItemData.itemInfo.item.effect;
                    }
                }
            }
            else 
            {
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar) 
                {
                    GameProxy.wareHouseExtendProxy.move(dragDropData);
                    return;
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBag && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar) 
                {
                    GameProxy.wareHouseExtendProxy.move(dragDropData);
                    return;
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse) 
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse) 
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    toItemIsExtend = false;
                    len = fromItemData.itemInfo.item.effect + 1;
                    showAlterWindow(Language.getString(42501), true);
                }
            }
            var loc2=pathOfDrag;
            switch (loc2) 
            {
                case BackPackWareHouseMoveType.WareHouseToWareHouseExtend:
                {
                    if (toIndex <= _cache.sbag.capacity) 
                    {
                        if (len >= 0) 
                        {
                            isTidy = false;
                            _proxy.move(dragDropData);
                        }
                        else 
                        {
                            isTidy = true;
                            showAlterWindow(Language.getString(42501), isTidy);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.WareHouseExtendToWareHouse:
                {
                    if (toIndex <= _cache.sbag.capacity) 
                    {
                        if (len > 0) 
                        {
                            isTidy = true;
                            showAlterWindow(Language.getString(42501), isTidy);
                        }
                        else 
                        {
                            isTidy = false;
                            _proxy.move(dragDropData);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.BackPackExtendToWareHouse:
                {
                    if (toIndex <= _cache.sbag.capacity) 
                    {
                        if (len > 0) 
                        {
                            isTidy = true;
                            showAlterWindow(Language.getString(42502), isTidy, BackPackWareHouseMoveType.BackPackExtendToWareHouse);
                        }
                        else 
                        {
                            isTidy = false;
                            _proxy.move(dragDropData, isTidy, BackPackWareHouseMoveType.BackPackExtendToWareHouse);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.BackPackToWareHouseExtend:
                {
                    if (toIndex <= _cache.sbag.capacity) 
                    {
                        if (len >= 0) 
                        {
                            isTidy = false;
                            _proxy.move(dragDropData, false, BackPackWareHouseMoveType.BackPackToWareHouseExtend);
                        }
                        else 
                        {
                            isTidy = true;
                            showAlterWindow(Language.getString(42501), isTidy, BackPackWareHouseMoveType.BackPackToWareHouseExtend);
                        }
                    }
                    break;
                }
            }
            return;
        }

        /* internal  */tabBarSelect(arg1: DataEvent): void
        {
            this.tabBarSelect_title = arg1.data;
            this.updateAllItems();
            return;
        }

        /* internal  */updateExtendDataChange(arg1: Object=null): void
        {
            var loc5=null;
            var loc6=0;
            var loc7=0;
            var loc1=arg1;
            if (!_view) 
            {
                return;
            }
            var loc2=new DataProvider();
            var loc3;
            var loc4=(loc3 = Cache.instance.pack.wareHouseExtendPackCache.getAllItems()).length;
            if (loc3.length <= 6) 
            {
                loc6 = 0;
                while (loc6 < loc3.length) 
                {
                    loc5 = this.getDataObjectByExtendItemData(loc3[loc6] as ItemData);
                    loc2.addItem(loc5);
                    ++loc6;
                }
                loc7 = 0;
                while (loc7 < 6 - loc3.length) 
                {
                    (loc5 = new Object()).source = GlobalClass.getBitmap("NoHole");
                    loc5.isOpened = false;
                    loc2.addItem(loc5);
                    ++loc7;
                }
                this._wareHouseModule.updateExtendAllItems(loc2);
                if (arg1) 
                {
                    if (arg1["selectIndex"] == -1) 
                    {
                        this._wareHouseModule.updateWareHouseExtendItemPanelSelectItem(-1);
                    }
                    else 
                    {
                        this._wareHouseModule.updateWareHouseExtendItemPanelSelectItem((arg1["selectIndex"] - 1));
                    }
                }
            }
            return;
        }

        /* internal  */getDataObjectByExtendItemData(arg1: ItemData): Object
        {
            var loc1=new Object();
            if (arg1 != ItemData.nullItemData) 
            {
                if (arg1) 
                {
                    loc1.itemData = arg1;
                    loc1.source = arg1.itemInfo.url;
                    loc1.isOpened = true;
                }
                else 
                {
                    loc1.isOpened = true;
                }
            }
            else 
            {
                loc1.source = GlobalClass.getBitmap("NoHole");
                loc1.isOpened = false;
            }
            return loc1;
        }

        /* internal  */updateCapacityChange(arg1: Object): void
        {
            var loc1=Cache.instance.pack.wareHousePackCache.capacity;
            var loc2=arg1 as SBagCapacityChangeMsg;
            var loc3=Math.abs(loc2.newCapacity - loc1);
            if (loc2.newCapacity > loc1) 
            {
                Cache.instance.pack.wareHousePackCache.addNullItemToEnd(loc3);
                this.updateItems(new Array<any>());
            }
            Cache.instance.pack.wareHousePackCache.capacity = loc2.newCapacity;
            this._wareHouseModule.updateCapacity(Cache.instance.pack.wareHousePackCache);
            return;
        }

        /* internal  */vipStorageOpenHandler(arg1: DataEvent): void
        {
            LayerManager.windowLayer.centerWindows(view, GameController.pack.view, 20);
            return;
        }

        /* internal  */npcOutHandler(arg1: DataEvent): void
        {
            if (!view.isHide) 
            {
                view.hide();
                if (!GameController.pack.view.isHide) 
                {
                    GameController.pack.view.hide();
                }
            }
            return;
        }

        /* internal  */fastUsePackage(arg1: DataEvent): void
        {
            var loc7=null;
            var loc1=arg1.data as WareHouseItem;
            if (!loc1.itemData) 
            {
                return;
            }
            var loc2=loc1.itemData.uid;
            var loc3=EPlayerItemPosType._EPlayerItemPosTypeWarehouse;
            var loc4=EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar;
            var loc5=Cache.instance.pack.wareHousePackCache.getIndexByUid(loc2);
            var loc6;
            if ((loc6 = Cache.instance.pack.wareHousePackCache.getFirstNullItemIndex()) == -1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(42505));
            }
            else 
            {
                loc7 = new DragDropData(loc3, loc4, loc2, loc5, loc6 + 1, null, null);
                GameProxy.wareHouseProxy.move(loc7);
            }
            return;
        }

        /* internal  */fastMoveItemToPack(arg1: DataEvent): void
        {
            var loc5=0;
            var loc7=0;
            var loc8=null;
            var loc1=arg1.data as WareHouseItem;
            if (!loc1.itemData) 
            {
                return;
            }
            var loc2=this._wareHouseModule.getWareHouseItemPanelSelectItem().itemData;
            var loc3=loc2.uid;
            var loc4=EPlayerItemPosType._EPlayerItemPosTypeWarehouse;
            if (ItemsUtil.isJewel(loc1.itemData)) 
            {
                loc5 = EPlayerItemPosType._EPlayerItemPosTypeStoneBag;
            }
            else if (ItemsUtil.isMagicWeapon(loc1.itemData)) 
            {
                loc5 = EPlayerItemPosType._EPlayerItemPosTypeAmuletBag;
            }
            else 
            {
                loc5 = EPlayerItemPosType._EPlayerItemPosTypeBag;
            }
            var loc6=Cache.instance.pack.wareHousePackCache.getIndexByUid(loc1.itemData.uid);
            if (ItemsUtil.isJewel(loc1.itemData)) 
            {
                loc7 = Cache.instance.pack.stonePackCache.getFirstNullItemIndex();
            }
            else if (ItemsUtil.isMagicWeapon(loc1.itemData)) 
            {
                loc7 = Cache.instance.pack.magicWeaponPackCache.getFirstNullItemIndex();
            }
            else 
            {
                loc7 = Cache.instance.pack.backPackCache.getFirstNullItemIndex();
            }
            if (loc7 == -1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(42506));
            }
            else 
            {
                loc8 = new DragDropData(loc4, loc5, loc3, loc6, loc7 + 1, null, null);
                GameProxy.packProxy.move(loc8);
            }
            return;
        }

        /* internal  */openWareHouseExtendItem(arg1: DataEvent): void
        {
            GameProxy.wareHouseExtendProxy.openExtendItem(PackCache.Type_WareHouseExtend);
            return;
        }

        /* internal  */onLoginGameSuccessHandler(arg1: DataEvent): void
        {
            this._wareHouseProxy.getBag();
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._wareHouseModule) 
            {
                this._wareHouseModule = new WareHouseModule();
                this._wareHouseModule.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.addToStage);
                this._wareHouseModule.addEventListener(WindowEvent.SHOW, this.showHander);
                this._wareHouseModule.addEventListener(EventName.WarePageTabBarSelect, this.pageTabBarSelect);
                this._wareHouseModule.addEventListener(EventName.WareTabBarSelect, this.tabBarSelect);
            }
            return this._wareHouseModule;
        }

        /* internal  */showHander(arg1: Object /* flash.events.Event */): void
        {
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            this._wareHouseModule.addEventListener(WindowEvent.CLOSE, this.closeHander);
            this._wareHouseModule.updateAccessMoney();
            return;
        }

        /* internal  */closeHander(arg1: Object /* flash.events.Event */): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            this._wareHouseModule.removeEventListener(WindowEvent.CLOSE, this.closeHander);
            return;
        }

        /* internal  */onMoneyUpdateHandler(arg1: SMoney): void
        {
            this._wareHouseModule.updateAccessMoney();
            return;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.WareHouse_DragInItem, this.dragInItem);
            Dispatcher.addEventListener(EventName.WareHouse_Tity, this.tidy);
            Dispatcher.addEventListener(EventName.WareHouse_Merge, this.merge);
            Dispatcher.addEventListener(EventName.WareHouse_TakeOut, this.takeOut);
            Dispatcher.addEventListener(EventName.Fast_USE_WareHousePackage, this.fastUsePackage);
            Dispatcher.addEventListener(EventName.Fast_Move_wareHouseItem_ToPack, this.fastMoveItemToPack);
            Dispatcher.addEventListener(EventName.OpenWareHouseExtendItem, this.openWareHouseExtendItem);
            Dispatcher.addEventListener(EventName.WareHouse_DragInExtendItem, this.wareHouse_DragInExtendItem);
            Dispatcher.addEventListener(EventName.StorageOpen, this.storageOpenHandler);
            Dispatcher.addEventListener(EventName.VIPStorageOpen, this.vipStorageOpenHandler);
            Dispatcher.addEventListener(EventName.AI_NpcOutDestance, this.npcOutHandler);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginGameSuccessHandler);
            NetDispatcher.addCmdListener(ServerCommand.WareHouseCapacityChange, this.updateCapacityChange);
            NetDispatcher.addCmdListener(ServerCommand.WareHouseDataChange, this.updateDataChange);
            NetDispatcher.addCmdListener(ServerCommand.WareHouseItemsChange, this.updateItems);
            NetDispatcher.addCmdListener(ServerCommand.WareHouseExtendItemsChange, this.updateExtendDataChange);
            NetDispatcher.addCmdListener(ServerCommand.WareHouseExtendDataChange, this.updateExtendDataChange);
            return;
        }

        /* internal  */addToStage(arg1: Object /* flash.events.Event */): void
        {
            this._wareHouseProxy.getBag();
            if (GameController.pack.view.isHide) 
            {
                GameController.pack.view.show();
            }
            this.updateExtendDataChange(null);
            return;
        }

        /* internal  */storageOpenHandler(arg1: DataEvent): void
        {
            LayerManager.windowLayer.centerWindows(view, GameController.pack.view, 20);
            this._wareHouseModule.checkGuide();
            return;
        }

        /* internal  */updateAllItems(arg1: Boolean=true): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=null;
            this.dataProvider = new DataProvider();
            var loc1=this._wareHouseCache._allItems.length;
            if (this._wareHouseCache) 
            {
                var loc7=this.tabBarSelect_title;
                switch (loc7) 
                {
                    case 0:
                    {
                        this.chooseAllLabel = true;
                        loc3 = this._wareHouseCache.getItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                        break;
                    }
                    case 1:
                    {
                        this.chooseAllLabel = false;
                        loc3 = this._wareHouseCache.getPropItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                        break;
                    }
                    case 2:
                    {
                        this.chooseAllLabel = false;
                        loc3 = this._wareHouseCache.getEquipItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                        break;
                    }
                    case 3:
                    {
                        this.chooseAllLabel = false;
                        loc3 = this._wareHouseCache.getJewelItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                        break;
                    }
                    case 4:
                    {
                        this.chooseAllLabel = false;
                        loc3 = this._wareHouseCache.getIllustrateItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                        break;
                    }
                    default:
                    {
                        this.chooseAllLabel = false;
                        loc3 = new Array<any>();
                        break;
                    }
                }
                loc4 = loc3.length;
                loc5 = 0;
                while (loc5 < loc4) 
                {
                    loc6 = this.getDataObjectByItemData(loc3[loc5] as ItemData);
                    this.dataProvider.addItem(loc6);
                    ++loc5;
                }
            }
            this._wareHouseModule.updateAllItems(this.dataProvider, arg1);
            return;
        }

        /* internal  */getDataObjectByItemData(arg1: ItemData): Object
        {
            var loc1=new Object();
            if (arg1 != ItemData.nullItemData) 
            {
                if (arg1) 
                {
                    loc1.itemData = arg1;
                    loc1.source = arg1.url;
                    loc1.isOpened = true;
                }
                else 
                {
                    loc1.isOpened = true;
                }
            }
            else 
            {
                loc1.source = GlobalClass.getBitmap("NoHole");
                loc1.isOpened = false;
            }
            return loc1;
        }

        /* internal  */pageTabBarSelect(arg1: DataEvent): void
        {
            var loc1=this._wareHouseModule.tabDict;
            loc1[this._wareHouseModule.tabBarSelect] = this._wareHouseModule.pageTabBarSelect;
            this.updateAllItems();
            return;
        }

        /* internal  */updateDataChange(arg1: Object=null): void
        {
            var loc1=null;
            var loc5=null;
            if (!_view) 
            {
                return;
            }
            this.dataProvider = new DataProvider();
            var loc6=this.tabBarSelect_title;
            switch (loc6) 
            {
                case 0:
                {
                    loc1 = this._wareHouseCache.getItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                    break;
                }
                case 1:
                {
                    loc1 = this._wareHouseCache.getPropItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                    break;
                }
                case 2:
                {
                    loc1 = this._wareHouseCache.getEquipItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                    break;
                }
                case 3:
                {
                    loc1 = this._wareHouseCache.getJewelItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                    break;
                }
                case 4:
                {
                    loc1 = this._wareHouseCache.getIllustrateItemsAtPage(this._wareHouseModule.pageTabBarSelect + 1, 30);
                    break;
                }
                default:
                {
                    loc1 = new Array<any>();
                    break;
                }
            }
            var loc2=loc1.length;
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc5 = this.getDataObjectByItemData(loc1[loc3] as ItemData);
                this.dataProvider.addItem(loc5);
                ++loc3;
            }
            this._wareHouseModule.updateAllItems(this.dataProvider);
            this._wareHouseModule.updateCapacity(this._wareHouseCache);
            if (arg1) 
            {
                if (arg1["selectIndex"] == -1) 
                {
                    this._wareHouseModule.updateWareHouseItemPanelSelectItem(-1);
                }
                else 
                {
                    this._wareHouseModule.updateWareHouseItemPanelSelectItem((arg1["selectIndex"] - 1));
                }
            }
            var loc4=Cache.instance.pack.wareHousePackCache;
            return;
        }

        /* internal  */dragInItem(arg1: DataEvent): void
        {
            var e: DataEvent;
            var dragDropData: DragDropData;
            var fromPosType: int;
            var fromIndex: int;
            var uidDrag: string;
            var toPosType: int;
            var toIndex: int;
            var toItemData: ItemData;
            var fromItemData: ItemData;
            var itemData: ItemData;
            var len: int;
            var toItemIsExtend: Boolean;
            var onCheckOp: Function;
            var cache;

            var loc1;
            dragDropData = null;
            toItemData = null;
            fromItemData = null;
            itemData = null;
            len = 0;
            toItemIsExtend = false;
            onCheckOp = null;
            cache = undefined;
            e = arg1;
            onCheckOp = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    GameProxy.packProxy.merge(EPlayerItemPosType._EPlayerItemPosTypeWarehouse, dragDropData.toItemData.uid, dragDropData.fromItemData.uid);
                }
                return;
            }
            this.page = this._wareHouseModule.pageTabBarSelect;
            dragDropData = e.data as DragDropData;
            fromPosType = dragDropData.fromPosType;
            fromIndex = dragDropData.fromIndex;
            uidDrag = dragDropData.uid;
            toPosType = dragDropData.toPosType;
            dragDropData.toIndex = dragDropData.toIndex + 30 * this.page;
            toIndex = dragDropData.toIndex;
            var loc2=fromPosType;
            switch (loc2) 
            {
                case 0:
                {
                    fromIndex = this._packCache.getIndexByUid(uidDrag);
                    dragDropData.fromIndex = fromIndex;
                    if (toIndex <= Cache.instance.pack.wareHousePackCache.sbag.capacity) 
                    {
                        this._wareHouseProxy.move(dragDropData);
                    }
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeStoneBag:
                {
                    fromIndex = Cache.instance.pack.stonePackCache.getIndexByUid(uidDrag);
                    dragDropData.fromIndex = fromIndex;
                    if (toIndex <= Cache.instance.pack.wareHousePackCache.sbag.capacity) 
                    {
                        this._wareHouseProxy.move(dragDropData);
                    }
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeAmuletBag:
                {
                    fromIndex = Cache.instance.pack.magicWeaponPackCache.getIndexByUid(uidDrag);
                    dragDropData.fromIndex = fromIndex;
                    if (toIndex <= Cache.instance.pack.wareHousePackCache.sbag.capacity) 
                    {
                        this._wareHouseProxy.move(dragDropData);
                    }
                    break;
                }
                case 1:
                {
                    if (!ItemsUtil.isMaxOverlay(dragDropData.fromItemData) && !ItemsUtil.isMaxOverlay(dragDropData.toItemData)) 
                    {
                        if (ItemsUtil.isSameItemData(dragDropData.fromItemData, dragDropData.toItemData)) 
                        {
                            GameProxy.packProxy.merge(EPlayerItemPosType._EPlayerItemPosTypeWarehouse, dragDropData.toItemData.uid, dragDropData.fromItemData.uid);
                            break;
                        }
                        if (ItemsUtil.isBindSameItemData(dragDropData.fromItemData, dragDropData.toItemData)) 
                        {
                            Alert.show(Language.getString(42500), null, Alert.OK | Alert.CANCEL, null, onCheckOp);
                            break;
                        }
                    }
                    fromIndex = Cache.instance.pack.wareHousePackCache.getIndexByUid(uidDrag);
                    cache = Cache.instance.pack.wareHousePackCache;
                    if (toIndex <= Cache.instance.pack.wareHousePackCache.sbag.capacity) 
                    {
                        this._wareHouseProxy.moveInBag(uidDrag, toIndex, fromIndex);
                    }
                    break;
                }
                case 3:
                {
                    break;
                }
                case 5:
                {
                    fromIndex = Cache.instance.pack.backPackExtendPackCache.getIndexByUid(uidDrag);
                    fromItemData = Cache.instance.pack.backPackExtendPackCache.getItemDataByIndex(fromIndex);
                    toItemData = Cache.instance.pack.wareHousePackCache.getItemDataByIndex(toIndex);
                    this.moveExtendItem(dragDropData, this._wareHouseProxy);
                    break;
                }
                case 6:
                {
                    fromIndex = Cache.instance.pack.wareHouseExtendPackCache.getIndexByUid(uidDrag);
                    fromItemData = Cache.instance.pack.wareHouseExtendPackCache.getItemDataByIndex(fromIndex);
                    toItemData = Cache.instance.pack.wareHousePackCache.getItemDataByIndex(toIndex);
                    this.moveExtendItem(dragDropData, this._wareHouseProxy);
                    break;
                }
            }
            return;
        }

        public tidy(arg1: DataEvent): void
        {
            this._wareHouseProxy.tidy();
            return;
        }

        public merge(arg1: DataEvent): void
        {
            GameProxy.packProxy.fastMerge(EPlayerItemPosType._EPlayerItemPosTypeWarehouse);
            return;
        }

        public /* const */posType: int=1;

        public /* const */extendPosType: int=6;

        private /* var */_wareHouseModule: WareHouseModule;

        private /* var */_wareHouseCache: WareHousePosTypeCache;

        private /* var */_wareHouseProxy: WareHouseProxy;

        private /* var */_wareHouseExtendProxy: WareHouseExtendProxy;

        private /* var */_packProxy: PackProxy;

        private /* var */_packCache: PackPosTypeCache;

        public /* var */chooseAllLabel: Boolean=true;

        private /* var */dataProvider: DataProvider;

        private /* var */_wareHouseArray: Array<any>;

        private /* var */tabBarSelect_title=0;

        private /* var */page: int;

        private /* var */_wareHouseExtendCache: WareHouseExtendPosTypeCache;
    }
